//
//  HTOrgStateView.swift
//  weibo
//
//  Created by JonsonLiu on 2017/3/3.
//  Copyright © 2017年 JonsonLiu. All rights reserved.
//

import UIKit
import SDWebImage

class HTOrgStateView: UIView {
    
    var  statesModel : StatesViewModel?{
    
        didSet{
//            let url = URL(string: (statesModel?.states?.user?.profile_image_url)!)
            guard let url = statesModel?.states?.user?.profile_image_url ,
                let urlString = URL(string: url)
            else {
                return
            }
            headImage.sd_setImage(with: urlString, placeholderImage: UIImage(named: "avatar_default_small"))
            
            
            nameLable.text = statesModel?.states?.user?.name
            
            vipImage.image = statesModel?.memberImage
            
            fromLable.text = statesModel?.sourceText
            
            contentLable.text = statesModel?.states?.text
        }
    }
    

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI(){
    
//        backgroundColor = UIColor(colorLiteralRed: Float(arc4random()%255)/255, green: Float(arc4random()%255)/255, blue: Float(arc4random()%255)/255, alpha: 1)
        
        addSubview(headImage)
        addSubview(nameLable)
        addSubview(vipImage)
        addSubview(fromLable)
        addSubview(dateLable)
        addSubview(verifiedImageView)
        addSubview(contentLable)
        
        
        
        headImage.snp.makeConstraints { (make) in
            make.top.leading.equalTo(10)
            make.size.equalTo(CGSize(width: 35, height: 35))
        }
        nameLable.snp.makeConstraints { (make) in
            make.top.equalTo(headImage)
            make.leading.equalTo(headImage.snp.trailing).offset(10)
        }
        dateLable.snp.makeConstraints { (make) in
            make.bottom.equalTo(headImage)
            make.leading.equalTo(headImage.snp.trailing).offset(10)
        }
        vipImage.snp.makeConstraints { (make) in
            make.top.equalTo(headImage)
            make.leading.equalTo(nameLable.snp.trailing).offset(10)
        }
        fromLable.snp.makeConstraints { (make) in
            make.top.equalTo(dateLable)
            make.leading.equalTo(dateLable.snp.trailing).offset(10)
        }
        verifiedImageView.snp.makeConstraints { (make) in
            make.centerX.equalTo(headImage.snp.trailing)
            make.centerY.equalTo(headImage.snp.bottom)
        }
        contentLable.snp.makeConstraints { (make) in
            make.leading.equalTo(headImage)
            make.top.equalTo(headImage.snp.bottom).offset(10)
        }
        self.snp.makeConstraints { (make) in
            make.bottom.equalTo(contentLable.snp.bottom).offset(10)
        }

    }
    //头像
    private lazy var headImage : UIImageView = UIImageView()
    //名字
    private lazy var nameLable : UILabel = {
    
        let nameLable = UILabel()
        nameLable.font = UIFont.systemFont(ofSize: 14)
        nameLable.textColor = UIColor.black
        nameLable.text = "天宇"
        return nameLable
    
    }()
    //VIP图片
    private lazy var vipImage : UIImageView = UIImageView(image: UIImage(named: "common_icon_membership_level1"))
    
    //来自哪里
    private lazy var fromLable : UILabel = {
    
        let  fromLable = UILabel()
        fromLable.font = UIFont.systemFont(ofSize: 10)
        fromLable.textColor = UIColor.black
        fromLable.text = "上海"
        return fromLable
    }()
    //时间
    private lazy var dateLable : UILabel = {
    
        let dateLable = UILabel()
        dateLable.text = "2017年3月2日"
        dateLable.textColor = UIColor.darkGray
        dateLable.font = UIFont.systemFont(ofSize: 10)
        return dateLable
        
    }()
    
    //大V
    private var verifiedImageView : UIImageView = UIImageView(image: UIImage(named: "avatar_vip"))
    
    //评论
    private var contentLable : UILabel = {
    
        let contentLbale = UILabel()
        
        contentLbale.font = UIFont.systemFont(ofSize: 15)
        contentLbale.textColor = UIColor.black
        contentLbale.preferredMaxLayoutWidth = UIScreen.main.bounds.size.width - 20
        contentLbale.numberOfLines = 0
        
        
        return contentLbale
    }()
}
